Visualizing spatio-temporal data

install & load packages

## Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: sp
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:robis':
## 
##     area
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo

Convert halibut dataframe to a sf object

The OBIS database provide a lot of context on the records.

##  [1] "rightsHolder"             "country"                 
##  [3] "date_year"                "institutionID"           
##  [5] "scientificNameID"         "year"                    
##  [7] "scientificName"           "dynamicProperties"       
##  [9] "dropped"                  "aphiaID"                 
## [11] "language"                 "phylumid"                
## [13] "familyid"                 "catalogNumber"           
## [15] "basisOfRecord"            "terrestrial"             
## [17] "superclass"               "modified"                
## [19] "maximumDepthInMeters"     "id"                      
## [21] "day"                      "order"                   
## [23] "superclassid"             "dataset_id"              
## [25] "collectionCode"           "speciesid"               
## [27] "date_end"                 "occurrenceID"            
## [29] "license"                  "date_start"              
## [31] "month"                    "genus"                   
## [33] "eventDate"                "brackish"                
## [35] "scientificNameAuthorship" "absence"                 
## [37] "subfamily"                "genusid"                 
## [39] "originalScientificName"   "marine"                  
## [41] "minimumDepthInMeters"     "subphylumid"             
## [43] "subfamilyid"              "institutionCode"         
## [45] "countryCode"              "date_mid"                
## [47] "eventTime"                "class"                   
## [49] "orderid"                  "datasetName"             
## [51] "kingdom"                  "specificEpithet"         
## [53] "classid"                  "phylum"                  
## [55] "species"                  "subphylum"               
## [57] "family"                   "category"                
## [59] "kingdomid"                "node_id"                 
## [61] "individualCount"          "fieldNumber"             
## [63] "type"                     "rights"                  
## [65] "recordedBy"               "datasetID"               
## [67] "locality"                 "taxonRank"               
## [69] "depth"                    "geometry"

We perform a visual check of the occurrences.

Visual representation per year

We can now build a representation of the occurrences per year, but firsts we have to extract the polygon for the area around the estuary.

## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries

Following, we can visualize the data

Practice

  1. Collect the occurences of your favorite species on OBIS.
    • robis::occurrence(scientificname = "Hippoglossus hippoglossus")
  2. Visualize the distribution of this species across several years using ggplot2.
  3. Produce count grids per year for this species.

Transform your data into spacetime classes

To perform spatio-temporal variograms with gstat, we need to convert our data into one of the following different spacetime classes of object. To build these objects, the best way is to use the stConstruct function in the spacetime package.

Get access to the data

Download PM10 air quality data

spacetime classes

  • full grid (STF), a combination of any sp object and any xts object to represent all possible locations on the implied space-time lattice;
  • sparse grid (STS), as STF, but contains only the non-missing space-time combinations on a space-time lattice;
  • irregular (STI), an irregular space-time data structure, where each point is allocated a spatial coordinate and a time stamp;
  • simple trajectories (STT), a sequence of space-time points that form trajectories.
##   station_id   pm10      dates      lng      lat
## 1    DEBB051  8.688 2001-06-08 14.05746 52.54136
## 2    DEBB051  7.354 2001-09-10 14.05746 52.54136
## 3    DEBB051 15.729 2001-10-10 14.05746 52.54136
## 4    DEBB051 26.312 2001-05-03 14.05746 52.54136
## 5    DEBB051 13.958 2001-10-28 14.05746 52.54136
## 6    DEBB051 39.188 2001-10-16 14.05746 52.54136
## [1] "STIDF"
## attr(,"package")
## [1] "spacetime"
## Object of class STFDF
##  with Dimensions (s, t, attr): (46, 28, 2)
## [[Spatial:]]
## Object of class SpatialPoints
## Coordinates:
##          min      max
## lng  6.28107 14.78617
## lat 47.80847 54.92497
## Is projected: FALSE 
## proj4string :
## [+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
## +towgs84=0,0,0]
## Number of points: 46
## [[Temporal:]]
##      Index              timeIndex    
##  Min.   :2005-06-02   Min.   : 1.00  
##  1st Qu.:2005-06-08   1st Qu.: 7.75  
##  Median :2005-06-15   Median :14.50  
##  Mean   :2005-06-15   Mean   :14.50  
##  3rd Qu.:2005-06-22   3rd Qu.:21.25  
##  Max.   :2005-06-29   Max.   :28.00  
## [[Data attributes:]]
##    station_id        pm10       
##  DESH001:  28   Min.   : 2.708  
##  DENI063:  28   1st Qu.:10.739  
##  DEUB038:  28   Median :14.191  
##  DEBE056:  28   Mean   :15.100  
##  DEBE032:  28   3rd Qu.:18.583  
##  (Other):1108   Max.   :53.292  
##  NA's   :  40   NA's   :40